-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All: Conflict notes will now populate a new field conflict_parent with the id of the conflict note. #5049
Conversation
Should be "conflict_parent_id" for consistency with the rest of the code base. Also please make sure that the is_conflict and your new field are in sync. If it's "1", your field should be set. If it's "0" it should be unset. I think there are some cases where it's not true. |
For instance when there's an unresolved conflict and you update Joplin to a version that includes this change. |
Hmm how do I recover the original note ID though ? Unless I set it when a conflict occurs, I believe there's no way to know. |
Normally the is_conflict field is set to 1 only during sync so I'm not sure how updating Joplin would cause an issue? |
I was trying to say that when @Ahmad45123 is going to add logic that relies on this field he can't assume that each conflicted note will have it set. Maybe there should be an option to set it manually? |
This field being set is what defines a conflicted note, so it would definitely be set. When a conflict is detected a new note is created with "is_conflict" set to 1. So it's not possible to create such note without the field being set. |
I meant the new field that this PR introduces -- conflict_parent_id |
Oh right! Ty for the note. Though, I think that will be handled in the plugins side? Maybe I'll use it if exists and otherwise ask the user to select the other note as some sort of backwards compatibly. I've also made it to reset |
packages/lib/services/synchronizer/Synchronizer.conflicts.test.ts
Outdated
Show resolved
Hide resolved
Ok so I've done:
|
I've fixed the issues. I hope it's okay now :) |
packages/lib/models/Note.test.ts
Outdated
const tmpConflictedNote = Object.assign({}, note1); | ||
delete tmpConflictedNote.id; | ||
tmpConflictedNote.is_conflict = 1; | ||
tmpConflictedNote.conflict_original_id = note1.id; | ||
const conflictedNote = await Note.save(tmpConflictedNote, { autoTimestamp: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't copy and paste large blocks of code in this codebase, it's just a mess to maintain otherwise. So please do this:
- Create a function in models/Note called
public async createConflictNote(sourceNote:NoteEntity, changeSource:number):Promise<NoteEntity>
- Make it create the conflict note and save it as in the code above.
- Then use that function in:
- Your two test units
- In lib/Synchronizer.ts
As a general rule if you see you are copying more than two or three lines of code, you should stop and think if the code can be refactored. Such refactoring improves the code quality because it wraps and names (using the function name) business logic and makes it re-usable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good now.
This is ready for another review. |
packages/lib/models/Note.test.ts
Outdated
// Source conflict should stay as is | ||
expect(conflictedNote.is_conflict).toBe(1); | ||
expect(conflictedNote.conflict_original_id).toBe(note1.id); | ||
expect(conflictedNote.parent_id).toBe(srcfolder.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to test the output of createConflictNote, it should be in a separate test, so please remove this part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll move it to a separate test.
packages/lib/models/Note.test.ts
Outdated
|
||
const conflictedNote = await Note.createConflictNote(note1, ItemChange.SOURCE_SYNC); | ||
|
||
// Move |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your comments you should explain why, not what. We know that a function called "Note.moveToFolder" is going to move the note to a folder, and a comment for this is just noise. I don't think you need to explain anything here, so please remove the comment.
packages/lib/models/Note.test.ts
Outdated
|
||
const conflictedNote = await Note.createConflictNote(note1, ItemChange.SOURCE_SYNC); | ||
|
||
// COPY File |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your comment explains nothing and is even confusing since we aren't moving files but notes, so please remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. Also no idea myself where did "File" come from 😂 sorry about that
packages/lib/models/Note.test.ts
Outdated
@@ -332,4 +333,49 @@ describe('models_Note', function() { | |||
expect(sortedNotes3[4].id).toBe(note2.id); | |||
})); | |||
|
|||
it('should copy conflicted note to target folder and cancel conflict', (async () => { | |||
// Prepare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
packages/lib/models/Note.test.ts
Outdated
})); | ||
|
||
it('should move conflicted note to target folder and cancel conflict', (async () => { | ||
// Prepare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
…g and copying notes.
Should be good for another review. :) |
Ok, you're the first pull request that uses the new GitHub Actions CI, so let's see if all the tests pass. |
Hmm I'll check the failed tests in a few minutes. |
If you are going to fix the test by committing and waiting for the full CI to run it might take a while. Instead you should look where the failure happens and run the tests locally inside the right package only. In that particular case, you can run |
I tried but I'm having trouble getting the server tests running locally. In fact, thats exactly why I missed this failing test. They all fail so I just ignored them. This is a portion of logs: https://pastebin.com/YXpyKNwx I think it has to do with Sqlite somehow. |
Could you use WSL instead? Otherwise you'll keep getting issues like this. |
Spent most of the day to get WSL working haha.. And now all tests pass locally though I've got no idea why did CI fail again :/ E: Please review my fix to that server test btw, I don't know how that all works yet and I've got no idea if my fix is correct haha |
There was a problem with the CI config but it works now, so let's merge. |
As the title says. Pretty simple change to be used with https://github.com/joplin/plugin-conflict-resolution